Linux下Node.js引用模块报错Error: Cannot find module 您所在的位置:网站首页 1 error cannot find lcrypto Linux下Node.js引用模块报错Error: Cannot find module

Linux下Node.js引用模块报错Error: Cannot find module

2023-06-21 22:18| 来源: 网络整理| 查看: 265

1,问题描述

背景:scrapyd上传的py文件,使用execjs调用Linux中的js文件,其中js引用了crypto-js,但是报错找不到这个模块(已安装)

//适配多个解密 const CryptoJS = require("crypto-js"); // const CryptoJS = require("/usr/local/lib/node_modules/crypto-js"); var _0x14e728 = new Date(); function hash(type, value){ if(type == 'md5'){ return CryptoJS.MD5(value).toString(); } if(type == 'sha1'){ return CryptoJS.SHA1(value).toString(); } if(type == 'sha256'){ return CryptoJS.SHA256(value).toString(); } } function cookies(_0x3d7469) { function _0x56cee0(_0xa58645, _0xf56c7e) { var _0x37f1b9 = _0x3d7469["chars"]["length"]; for (var _0x268aea = 0; _0x268aea var _0x235ad1 = _0xf56c7e[0] + _0x3d7469["chars"]["substr"](_0x268aea, 1) + _0x3d7469["chars"]["substr"](_0x4614fb, 1) + _0xf56c7e[1]; if (hash(_0x3d7469['ha'], _0x235ad1) == _0xa58645) { return [_0x235ad1, new Date() - _0x14e728]; } } } } var _0x732635 = _0x56cee0(_0x3d7469["ct"], _0x3d7469["bts"]); return {'__jsl_clearance_s' : _0x732635[0]}; } // _0x3d7469 = { // "bts": ["1684222849.145|0|NKW", "el7hb7LKwY%2BSlBVcjmZAyI%3D"], // "chars": "JdzZAHOVmwUgOAZudnYlem", // "ct": "a3a56368e8dd9b39a02bf1dba60dc39eaaf6a0fe2c8c868c902074dfb4062e82", // "ha": "sha256", // "tn": "__jsl_clearance_s", // "vt": "3600", // "wt": "1500" // } // console.info(cookies(_0x3d7469)) 2,解决办法 2.1方法一

1, 执行命令 npm -g root,查看全局安装的 Node.js 模块所在的路径 2, 将引用模块的路径改为绝对路径const CryptoJS = require(“/usr/local/lib/node_modules/crypto-js”); 这个虽然能解决,但是没有逼格,所以请出二号选手

2.2方法二

1,首先cd到文件所在的位置,执行命令npm init,这个命令用于初始化一个新的 Node.js 项目的命令。它会创建一个 package.json 文件 2,然后在这个位置npm install [你要安装模块],再去执行js文件node xxx.js,就可以了 3,这里就不用再修改绝对路径了 在这里插入图片描述

在这里插入图片描述 注:后面我将这个js目录移到/opt/lily/js目录下面又报找不到这个模块的错

方法三

在这里插入图片描述

看日志,可以看到说是当前模块加载错误的来源是位于 “/opt/lily” 目录下的一个文件,所以我们要在这个目录下执行命令npm init,然后再npm install [你要安装模块]



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有